<?php

class IndexController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {

    }
    
    public function subscribeAction()
    {
    	$form = new Application_Form_Subscribe();
    	$this->view->form = $form;
    	
    	if ($this->_request->isPost ()) {
    		$formData = $this->_request->getPost ();
    		if ($form->isValid ( $formData )) {
    			$login = $form->getValue('login');
    			$nom = $form->getValue('nom');
    			$prenom = $form->getValue('prenom');
    			$salt = substr($login, 0, 3);
    			$password = sha1($salt.$form->getValue('pass').$salt);
    			
    			// enregistrement du nouvel utilisateur en BD
    			$userMapper = new Application_Model_UtilisateurMapper();
    			$user = new Application_Model_Utilisateur();
    			$user->setLogin($login)
    				->setNom($nom)
    				->setPrenom($prenom)
    				->setMdp($password);
    			
    			$userMapper->save($user);
    			
    			// envoi d'un mail avant activation des droits
    		}
    	}
    }

}

